<template>
	<view>
		<!-- 热销商品 -->
		<view class="shop-popular container">
			<!-- {{pageData.name}} -->

			<!-- 头部标题 -->
			<view class="popular-head">
				<view class="left">
					<view class="title">{{appStyle.home_activity_title}}</view>
					<span></span>
					<view class="desc">{{appStyle.home_activity_text}}</view>
				</view>
				<!-- <view class="more"  @tap="checkMore('热销')">查看更多</view> -->

				<!-- 顶部三个商品 -->
					<swiper :indicator-dots="false" :duration="1000" display-multiple-items="3" class="popular-list-head">
						<!-- <swiper-item>
							<view class="swiper-item"></view>
						</swiper-item> -->

						<swiper-item class="popular-item" v-for="(item, index) in row1" :key="index"
							@tap="onGoods(item.goods_id)">
							<view class="img-bg"
								:style="{background: `url(${$wanlshop.oss(item.img_url)})`}"></view>
						</swiper-item>
					</swiper>

				<image class="popular-bg" :src="$wanlshop.oss(appStyle.hot_sale_image)" mode="widthFix"></image>
			</view>

			<!-- 商品列表 -->
			<view class="popular-list">



				<!-- 其余商品 -->
				<view class="popular-list-body" :class="row.length <= 2 ? `col-${row.length}` : 'col-2'">
					<view class="popular-item" v-for="(item, index) in row" :key="index" @tap="onGoods(item.goods_id)">
						<image :src="$wanlshop.oss(item.img_url)" mode="widthFix"></image>
					</view>
				</view>

			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		name: "index-popular",
		props: {
			pageData: {
				type: Array,
				default: function() {
					return [];
				}
			}
		},
		data() {
			return {
				row1: [],
				row: [],
			};
		},
		computed: {
			...mapState(['common']),
			// 全局样式
			appStyle() {
				return this.common.appStyle;
			}
		},

		watch: {
			pageData(n, o) {
				this.row1 = [];
				this.row = [];
				n.forEach(item => {
					if (item.row == 1) {
						this.row1.push(item)
					} else {
						this.row.push(item)
					}
				})
			}
		},
		methods: {
			//  查看更多
			checkMore(text) {
				// this.$wanlshop.to(`/pages/product/list?type=goods&search=${text}`, 'fade-in', 100);
			},
		}
	}
</script>

<style scoped lang="scss">
	.container {
		// background-color: #fdb3dc;
		border-radius: 16rpx;
		padding: 0 20rpx;
		box-sizing: border-box;

		.popular-head {
			width: 100%;
			background-size: 100%;
			background-position: center;
			// background-color: #11e195;
			color: #ffffff;
			padding: 16rpx;
			border-radius: 16rpx 16rpx 0 0;
			font-size: 26rpx;
			background-size: 100% !important;
			background-repeat: no-repeat !important;
			border-radius: 0 0 20rpx 20rpx;
			overflow: hidden;
			margin-bottom: 14rpx;
			position: relative;

			.popular-bg {
				position: absolute;
				top: 0;
				left: 0;
				width: 100%;
				height: 100%;
				z-index: -1;
			}


			.left {
				display: flex;
				justify-content: space-between;
				align-items: center;
				gap: 30rpx;
				height: 100%;
				margin-bottom: 20rpx;
				position: relative;
				z-index: 1;

				.title {
					font-size: 36rpx;
					margin-left: 16rpx;
				}

				span {
					display: block;
					width: 4rpx;
					height: 60%;
					background-color: #ffffff80;
				}

				.desc {
					color: #512D0D;
					transform: translateY(-4rpx);
				}
			}

			.popular-list-head {
				width: 100%;
				height: 240rpx;
				/* display: grid;
				grid-template-columns: repeat(1);
				gap: 10rpx; */

				.popular-item {
					// box-shadow: 0px 0px 12rpx 0px rgba(0, 0, 0, 0.2);
					border-radius: 12rpx;
					overflow: hidden;
					// border: 1px solid red;
					height: fit-content !important;
					padding: 10rpx;
					box-sizing: border-box;

					.img-bg {
						background-size: cover !important;
						background-position: center !important;
						padding-top: 100%;
						border-radius: 12rpx;
					}
				}
			}
		}

		.popular-list {

			.popular-item {
				// border: 2rpx solid red;
				// box-shadow: 0px 0px 12rpx 0px rgba(0, 0, 0, 0.2);
				overflow: hidden;

				.img-bg {
					background-size: cover;
					height: 260rpx;
					border-radius: 12rpx;
				}
			}

			.popular-list-body {
				display: grid;
				grid-template-columns: repeat(2, 1fr);
				gap: 14rpx 10rpx;

				&.col-1 {
					grid-template-columns: repeat(1, 1fr);
				}

				&.col-2 {
					grid-template-columns: repeat(2, 1fr);
				}

				.popular-item {
					border-radius: 20rpx;

					image {
						width: 100%;
						display: block;
					}
				}
			}

		}
	}
</style>